package com.hx.reporter.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hx.common.annotation.Log;
import com.hx.common.core.controller.BaseController;
import com.hx.common.core.domain.AjaxResult;
import com.hx.common.enums.BusinessType;
import com.hx.reporter.domain.ChatRecord;
import com.hx.reporter.service.IChatRecordService;
import com.hx.common.utils.poi.ExcelUtil;
import com.hx.common.core.page.TableDataInfo;

/**
 * 聊天记录Controller
 * 
 * @author ${author}
 * @date 2023-05-28
 */
@RestController
@RequestMapping("/record")
public class ChatRecordController extends BaseController {
    @Autowired
    private IChatRecordService chatRecordService;

    /**
     * 查询聊天记录列表
     */
    @PreAuthorize("@ss.hasPermi('reporter:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(ChatRecord chatRecord)
    {
        startPage();
        List<ChatRecord> list = chatRecordService.selectChatRecordList(chatRecord);
        return getDataTable(list);
    }

    /**
     * 导出聊天记录列表
     */
    @PreAuthorize("@ss.hasPermi('reporter:record:export')")
    @Log(title = "聊天记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ChatRecord chatRecord)
    {
        List<ChatRecord> list = chatRecordService.selectChatRecordList(chatRecord);
        ExcelUtil<ChatRecord> util = new ExcelUtil<ChatRecord>(ChatRecord.class);
        util.exportExcel(response, list, "聊天记录数据");
    }

    /**
     * 获取聊天记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('reporter:record:query')")
    @GetMapping(value = "/{chatRecordId}")
    public AjaxResult getInfo(@PathVariable("chatRecordId") String chatRecordId)
    {
        return success(chatRecordService.selectChatRecordByChatRecordId(chatRecordId));
    }

    /**
     * 新增聊天记录
     */
    @PreAuthorize("@ss.hasPermi('reporter:record:add')")
    @Log(title = "聊天记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChatRecord chatRecord)
    {
        return toAjax(chatRecordService.insertChatRecord(chatRecord));
    }

    /**
     * 修改聊天记录
     */
    @PreAuthorize("@ss.hasPermi('reporter:record:edit')")
    @Log(title = "聊天记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChatRecord chatRecord)
    {
        return toAjax(chatRecordService.updateChatRecord(chatRecord));
    }

    /**
     * 删除聊天记录
     */
    @PreAuthorize("@ss.hasPermi('reporter:record:remove')")
    @Log(title = "聊天记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{chatRecordIds}")
    public AjaxResult remove(@PathVariable String[] chatRecordIds)
    {
        return toAjax(chatRecordService.deleteChatRecordByChatRecordIds(chatRecordIds));
    }
}
